#!/bin/bash
function rotate(){
INTERVAL=0.1 # 最佳间隔
RCOUNT="0"
echo -n 'Cleaning... '
while :
do
    ((RCOUNT = RCOUNT + 1))
    case $RCOUNT in
        1) echo -e '-\b\c'
            sleep $INTERVAL
            ;;
        2) echo -e '\\\b\c'
            sleep $INTERVAL
            ;;
        3) echo -e '|\b\c'
            sleep $INTERVAL
            ;;
        4) echo -e '/\b\c'
            sleep $INTERVAL
            ;;
        *) RCOUNT=0
            ;;
    esac
done
}

node_install_path="/opt/node-v12.16.1-linux-x64/"

echo "You Must Use ROOT To Links"
echo "Start to install Node.js and Git"
echo ""
mkdir -p ${node_install_path}
cd ${node_install_path}
sleep 3

# node
wget https://npm.taobao.org/mirrors/node/v12.16.1/node-v12.16.1-linux-x64.tar.gz

# Unpack
echo "Unpacking..."
echo "> tar -zxf node-v12.16.1-linux-x64.tar.gz"
tar -zxf node-v12.16.1-linux-x64.tar.gz
rm -rf node-v12.16.1-linux-x64.tar.gz
echo "complete."

sleep 1

echo "Linking..."
echo "> ln -s ${node_install_path}/node-v12.16.1-linux-x64/bin/node /usr/bin/node"
echo "> ln -s ${node_install_path}/node-v12.16.1-linux-x64/bin/npm /usr/bin/npm"
rm -rf /usr/bin/node /usr/bin/npm
ln -s ${node_install_path}/node-v12.16.1-linux-x64/bin/node /usr/bin/node
ln -s ${node_install_path}/node-v12.16.1-linux-x64/bin/npm /usr/bin/npm
echo "complete."

sleep 1

echo "--------------- Node Version ---------------"
node_version=`node -v`
npm_version=`npm -v`
echo " node: ${node_version}"
echo " npm: ${npm_version}"
echo "--------------- Node Version ---------------"

sleep 3
cd ..

echo "Installing git...";
yum install -y git
apt install -y git
pacman -S git


rotate &
trap "kill -9 $BG_PID" INT
ROTATE_PID=$!
echo "
--------------- Thanks ---------------
  Complete! 
       --By Pig2333
--------------- Thanks ---------------

Install Path : ${node_install_path}
"
touch don
rm -rf don
sleep 5
kill -9 $ROTATE_PID
